#ifndef FACE_ATTEND_SERVER_PUBLIC_H
#define FACE_ATTEND_SERVER_PUBLIC_H
#include <math.h>
#include <Mmsystem.h>
#include "IrIdentify/IrIdentify.h"
//#include "TiJpeg.h"
#include "BtnST.h"
#include "TiCapture2/TiCapture2.h"
//#include "mkey.h"
//#include "mkeyerr.h"
#pragma warning(disable:4786 4305 4101)
#include <fstream>
#include <iterator>
#include <algorithm>
#include <string>
#include <vector>
//#include "dib.h"

using namespace std;
#define WM_MY_TRAY_NOTIFICATION WM_USER+105
#define WM_PROCESS_LOG_PACKET WM_USER+110

#define APP_BACK_COLOR RGB(228,228,228)
#define EDIT_CTRL_COLOR RGB(36,100,144)
#define BUTTON_COLOR RGB(255,0,0)
///
#define BTN_INACTIVE_BG_COLOR RGB(215,215,215)//(228,228,215)
#define BTN_INACTIVE_FG_COLOR RGB(0,0,0)
#define BTN_ACTIVE_BG_COLOR RGB(237,233,207)
#define BTN_ACTIVE_FG_COLOR RGB(0,0,0)

#define Faceprint_Feature_Num  20
#define ShowImageWidth  56
#define ShowImageHeight 56
#define FRAME_WIDTH 640
#define FRAME_HEIGHT 480


#define GetRandom(min,max) rand()*((float)((max)-(min)))/(float)(RAND_MAX)+(min)


struct EnrollBmpBufInfo
{
	BYTE* m_pBmpBuf;
	long m_nWidth;
	long m_nHeight;
	EnrollBmpBufInfo(long nWidth,long nHeight)
	{
		m_nWidth=nWidth;
		m_nHeight=nHeight;
		m_pBmpBuf=new BYTE[m_nWidth*m_nHeight*3];
	};
	~EnrollBmpBufInfo()
	{
		delete []m_pBmpBuf;
		m_pBmpBuf=NULL;
	};
};
struct GrayBufInfo
{
	BYTE* pGrayBuf;
	long m_nWidth;
	long m_nHeight;
	GrayBufInfo(long nWidth,long nHeight)
	{
		m_nWidth=nWidth;
		m_nHeight=nHeight;
		pGrayBuf=new BYTE[m_nWidth*m_nHeight];
	}
	~GrayBufInfo()
	{
		delete []pGrayBuf;
		pGrayBuf=NULL;
		m_nWidth=0;
		m_nHeight=0;
	}
};

struct PersonInfo
{
	char sStuffName[MAX_PATH];
	char sStuffPSW[MAX_PATH];
	char sStuffDomain[MAX_PATH];
	long nFeatureNum;
	BYTE* pFeatureBuf;

	PersonInfo()
	{
		pFeatureBuf=NULL;
	};
	~PersonInfo()
	{
		delete []pFeatureBuf;
		pFeatureBuf=NULL;
	};

};

extern HMODULE g_hModule;
extern CString g_strAppPath;
extern int g_nVideoMode;
extern long g_nFeatureSize;
extern EnrollBmpBufInfo* g_pIrEnrollBmpBufInfo;
extern BYTE* g_pEnrollFeatureBuf;
extern CDWordArray g_SelGrayBufInfoArray;

extern BYTE* Rotate(BYTE* pRgbBuf,long& nWidth,long& nHeight,float angle);
extern BOOL BGRFromRGB(BYTE *buf, UINT widthPix, UINT height);
extern BOOL MirrorDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight, BOOL bDirection,int nImageBits);
extern void DrawBmpBuf(BITMAPINFOHEADER& bih,BYTE* pDataBuf,HWND hShowWnd,BOOL bFitWnd);
extern void ContructBih(int nWidth,int nHeight,BITMAPINFOHEADER& bih);
extern void TiDrawFaceRects(BYTE* pRgbBuf,int nBufWidth,int nBufHeight,
				   RECT* pFaceRects,int nRectNum,
				   COLORREF color,int nPenWidth);
extern BOOL GetCBitmap(BITMAPINFOHEADER* pBih, BYTE* pDataBuf,CBitmap &bmp);
extern BOOL ResampleBmp(BITMAPINFOHEADER& bih, BYTE* inBuf,int newx,int newy,BYTE* outBuf);
extern void GetPartImage( BYTE* image, int imageWidth, int imageHeight, BYTE* part,  int left,int top, int right ,int bottom );
extern BYTE* LoadBmpFromFile(LPCTSTR strFileName,BITMAPINFOHEADER& bih);
extern BOOL SaveBufToBmpFile( BYTE* buf, LPBITMAPINFOHEADER lpBih, LPCSTR strFileName );
extern HBITMAP DrawCrossEyes(BYTE* image, POINT LEye,POINT REye,int nWidth,int nHeight,COLORREF color,int nPenWidth,int nCrossSize);
extern void DeleteDirFile(CString sPath);
extern BOOL DebugInfo(const char* pDebugInfo);
extern double ScoreMap(double nSourceScore,double nFAR);
extern void DoNetSend(CString strComputer, CString strMessage);
extern int SynCheck(BYTE *Image, int Width, int Height);
extern void SaveBmp8File(CString szFileName, BYTE * srcImage, int Width, int Height);
extern void _DebugInfo(LPCSTR szLogFile,LPCSTR szInfo, ...);
extern LPVOID LoadDataResource(LPCTSTR lpResName,const char *name);
extern long ChangeRGBtoYII(BYTE * pRgbBuf,RECT* rectcome,int weidth,int heigth);
extern void TiDrawFaceRectsII(BYTE* pRgbBuf,int nBufWidth,int nBufHeight,POINT* lefteye,POINT* righteye,
							  COLORREF color,int nPenWidth);
extern void DrawRect(BYTE* pRgbBuf,int x1,int x2,int x3,int x4,int y1,int y2,int y3,int y4,int nCrossSize,
			  int nBufWidth,int nBufHeight,int nPenWidth, COLORREF color,POINT LEye,POINT REye );

#endif